using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

namespace InfiniTec.Threading
{
    class AsyncOperationIdentifier: IEquatable<AsyncOperationIdentifier>
    {
        private readonly string _Name;
        private readonly object _UserState;


        public bool Equals(AsyncOperationIdentifier asyncOperationIdentifier)
        {
            if (asyncOperationIdentifier == null) return false;
            return Equals(_Name, asyncOperationIdentifier._Name) && Equals(_UserState, asyncOperationIdentifier._UserState);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(this, obj)) return true;
            return Equals(obj as AsyncOperationIdentifier);
        }

        public override int GetHashCode()
        {
            return _Name.GetHashCode() + 29*(_UserState != null ? _UserState.GetHashCode() : 0);
        }

        public AsyncOperationIdentifier(string name, object userState)
        {
            if(string.IsNullOrEmpty(name)) throw new ArgumentNullException("name");

            _Name = name;
            _UserState = userState;
        }


        public string Name { get { return _Name; } }
        public object UserState { get { return _UserState; } }
    }
}
